package edu.princeton.cogsci.wn.ascii;

import java.util.*;
import edu.princeton.cogsci.wn.*;

/**
 *  This class models a unique identifier for a synset, in the ASCII WordNet
 *  implementation.
 */

public class AsciiSynsetKey implements SynsetKey
{
  // These members need package security so that they can be used from
  // AsciiWordNetImpl.

  int pos;
  int offset;

  AsciiSynsetKey( String key )
  {
    try
    {
      StringTokenizer st = new StringTokenizer( key, ":" );
      this.pos = Integer.parseInt( st.nextToken( ) );
      this.offset = Integer.parseInt( st.nextToken( ) );
    }
    catch ( NoSuchElementException nsee )
    {
      throw new WordNetException( "Malformed synset key: " + key );
    }
  }

  AsciiSynsetKey( int pos, int offset )
  {
    this.pos = pos;
    this.offset = offset;
  }

  // These functions (I think) are used by Hashtable...

  public String toString( )
  {
    return pos + ":" + offset;
  }

  public int hashCode( )
  {
    return offset * 10 + pos;
  }

  public boolean equals( Object other )
  {
    if ( other instanceof AsciiSynsetKey )
      return hashCode( ) == other.hashCode( );
    return false;
  }
}
